package ch.bfh.swos.learnaid.service;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import ch.bfh.swos.learnaid.service.dto.QListDTO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/serviceContext.xml")
public class QListeServiceIT {

    @Inject
    private QListService qListService;

    @Test
    public void test() {
        
        // Create
        QListDTO newQList = new QListDTO();
        newQList.setName("name");
        newQList= qListService.create(newQList);

        // Read
        QListDTO readQList= qListService.read(newQList.getId());
        Assert.assertTrue(newQList.getName().equals(readQList.getName()));

        // Update
        readQList.setName("newName");
        readQList = qListService.update(readQList);
        QListDTO updatedList= qListService.read(readQList.getId());
        Assert.assertTrue(readQList.getName().equals(updatedList.getName()));

        // Delete
        qListService.delete(updatedList);
        QListDTO deletedQList = qListService.read(readQList.getId());
        Assert.assertNull(deletedQList);
    }

}
